import sys
import os
import re

def count_characters(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        text = file.read()
    return len(text)

def count_words(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        text = file.read()
    words = text.split()
    return len(words)

def count_sentences(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        text = file.read()
    sentences = re.split(r'[.!?]+', text)
    return len(sentences) - (1 if text.endswith('.') else 0)

def count_lines(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        lines = file.readlines()
    return len(lines)

def count_empty_lines(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        lines = file.readlines()
    return sum(1 for line in lines if line.strip() == "")

def count_comment_lines(filename):
    with open(filename, 'r', encoding='utf-8') as file:
        lines = file.readlines()
    return sum(1 for line in lines if line.strip().startswith('#'))

def main():
    if len(sys.argv) != 3:
        print("Usage: wc.exe [option] [filename]")
        return

    option = sys.argv[1]
    filename = sys.argv[2]

    if not os.path.isfile(filename):
        print(f"Error: File '{filename}' not found.")
        return

    if option == '-c':
        print(f"Character count: {count_characters(filename)}")
    elif option == '-w':
        print(f"Word count: {count_words(filename)}")
    elif option == '-s':
        print(f"Sentence count: {count_sentences(filename)}")
    elif option == '-l':
        print(f"Line count: {count_lines(filename)}")
    elif option == '-e':
        print(f"Empty line count: {count_empty_lines(filename)}")
    elif option == '-co':
        print(f"Comment line count: {count_comment_lines(filename)}")
    else:
        print("Invalid option.")

if __name__ == "__main__":
    main()
